<?php

/**
 * 宣教分类
 */

namespace app\common\model;

class PropagandaEducationClass extends BaseModel
{
    protected $name = "propaganda_education_class";

    protected $type = [
        'isopen' => 'integer',
        'deleted_at' => 'integer',
    ];

    /**
     * 获取数据列表
     */
    public function getList()
	{
		return $this->order('created_at', 'desc')
        ->paginate($this->pageLimit);
	}

    /**
     * 添加数据
     * @param array $data
     * @return string
     */
    public function addData(array $data): string
    {
        //添加时销毁自带的主键id
        unset($data['id']);
        return $this->save($data);
    }

    /**
     * 更新数据
     * @param array $data
     * @return bool
     */
    public function saveData($id, array $param): bool
    {
        $data['deleted_at'] = (int)$param['deleted_at'];
        $data['isopen']     = (int)$param['isopen'];
        $data['name']       = $param['name'];
        $model = self::find($id);
        return $model->save($data);
    }

    /**
     * 获取分类数据
     */
    public function getDatas()
	{
		return $this->field('id,name')->select()->toArray();
	}
    
    /**
     * 获取绑定过宣教的分类
     */
    public function getEdClass()
    {
        return $this
            ->where('isopen', 1)
            ->field('id,name,classify')
            ->order('created_at', 'desc')
            ->paginate($this->pageLimit);
    }
}